package com.website.view
{
	import com.bakh.picWall.Bakh3DWall;
	import com.greensock.TweenMax;
	import com.website.event.FadeOutEvent;
	import com.website.util.Constant;
	import com.website.view.component.BakhTextFiled;
	import com.website.view.component.ClickBtnComp;
	import com.website.view.component.ScreenBtn;
	
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.display.StageDisplayState;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * 欢迎页 
	 * @author User
	 * 
	 */	
	public class WelcomePage extends Sprite
	{
		
		private var _openStandScreen:ScreenBtn;
		private var _openFullScren:ScreenBtn;
		private var _compNameTxt:BakhTextFiled;
		private var _englishBtn:ScreenBtn;
		private var _chineseBtn:ScreenBtn;
		private var _bsSP:Sprite;
		private var _bakh3DWall:Bakh3DWall
		public function WelcomePage()
		{
			_openStandScreen = new ScreenBtn("Enter Standard",Constant.hotColor);
			_openFullScren = new ScreenBtn("Enter Fullscreen", Constant.hotColor,true);
			_englishBtn = new ScreenBtn("English",Constant.hotColor);
			_chineseBtn = new ScreenBtn("中文",Constant.hotColor);
			_compNameTxt = new BakhTextFiled("BAKH-architecture",50,"0xFF3200");
			_compNameTxt.x = (Constant.gridCurrW - _compNameTxt.width)  /2;
			_compNameTxt.y = Math.round(Constant.gridY + Constant.gridCurrH) / 2;
			_bsSP = new Sprite();
			_bsSP.graphics.beginFill(0xFFFFFF,0);
			_bsSP.graphics.drawRect(0,0,LayerManager.stage.stageWidth,LayerManager.stage.stageHeight);
			_bsSP.graphics.endFill();
			addChild(_bsSP);
			addChild(_compNameTxt);
			addChild(_openStandScreen);
			addChild(_openFullScren);
			addChild(_englishBtn);
			addChild(_chineseBtn);
			_bakh3DWall =  new Bakh3DWall();
			addChild(_bakh3DWall);
			_bakh3DWall.y = -100;
			doResize();
			_bsSP.addEventListener(MouseEvent.CLICK, onClick)
			_openFullScren.addEventListener(MouseEvent.CLICK, onFullBtnClick);
			_openStandScreen.addEventListener(MouseEvent.CLICK, onClick);
			_englishBtn.addEventListener(MouseEvent.CLICK, onClick);
			_chineseBtn.addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function onFullBtnClick(ev:MouseEvent):void
		{
			LayerManager.stage.displayState = StageDisplayState.FULL_SCREEN;
			onClick(ev);
		}
		
		private function doResize():void
		{
			if (_openStandScreen != null)
			{
				_openStandScreen.x = Constant.gridX;
				_openStandScreen.y = Math.round(Constant.gridY + Constant.gridCurrH);
				_openFullScren.x = Math.round(Constant.gridX + 2 * (Constant.unitW + Constant.gutterW));
				_openFullScren.y = _englishBtn.y = _chineseBtn.y= Math.round(Constant.gridY + Constant.gridCurrH);
				_englishBtn.x = _openFullScren.x + _openFullScren.width * 2;
				_chineseBtn.x = _englishBtn.x + _englishBtn.width * 2;
			}
		}
		
		private function onClick(ev:MouseEvent):void
		{
			fadeOutShell();
		}
		
		private function fadeOutShell() : void
		{
			this.blendMode = BlendMode.LAYER;
			TweenMax.to(this, Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:dispathFadeOutEvent});
		}
		
		private function dispathFadeOutEvent():void
		{
			dispatchEvent(new FadeOutEvent());
		}
	}
}